package com.ins.controller;

import com.ins.common.utils.Result;
import com.ins.model.entity.AppWallet;
import com.ins.model.vo.AppWalletVO;
import com.ins.service.AppWalletService;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Map;

/**
 * 钱包
 *
 * @author ins
 * @since 2024-05-14
 */
@RestController
@RequestMapping("/wallet")
public class AppWalletController {

    @Resource
    private AppWalletService appWalletService;

    /**
     * 添加 钱包
     *
     * @param appWallet 钱包
     * @return {@code true} 添加成功，{@code false} 添加失败
     */
    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody AppWallet appWallet) {
        return Result.ok(appWalletService.save(appWallet));
    }


    /**
     * 根据主键删除钱包
     *
     * @param id 主键
     * @return {@code true} 删除成功，{@code false} 删除失败
     */
    @DeleteMapping("/remove/{id}")
    public Result<Boolean> remove(@PathVariable Serializable id) {
        return Result.ok(appWalletService.removeById(id));
    }


    /**
     * 根据主键更新钱包
     *
     * @param appWallet 钱包
     * @return {@code true} 更新成功，{@code false} 更新失败
     */
    @PutMapping("/update")
    public Result<Boolean> update(@RequestBody AppWallet appWallet) {
        return Result.ok(appWalletService.updateById(appWallet));
    }


    /**
     * 查询所有钱包
     *
     * @return 所有数据
     */
    @PostMapping("/withdrawals")
    public Result<String> withdrawals(@RequestBody Map<String, String> money) {
        return Result.ok(appWalletService.withdrawals(money));
    }


    /**
     * 根据钱包主键获取详细信息。
     *
     * @param id appWallet主键
     * @return 钱包详情
     */
    @GetMapping("/getInfo")
    public Result<AppWalletVO> getInfo() {
        return Result.ok(appWalletService.getInfo());
    }


    /**
     * 分页查询钱包
     *
     * @param page 分页对象
     * @return 分页对象
     */
    @GetMapping("/page")
    public Result<Page<AppWallet>> page(Page<AppWallet> page) {
        return Result.ok(appWalletService.page(page));
    }
}